package com.veepeak.server.service;

import com.veepeak.server.common.BaseRepository;
import com.veepeak.server.common.BaseService;
import com.veepeak.server.domain.Vehicle;
import com.veepeak.server.domain.VehicleMake;
import com.veepeak.server.domain.VehicleModel;
import com.veepeak.server.repository.VehicleMakeRepository;
import com.veepeak.server.repository.VehicleModelRepository;
import com.veepeak.server.repository.VehicleRepository;
import io.swagger.annotations.ApiImplicitParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class VehicleService extends BaseService<Vehicle,String> {
    @Autowired
    private VehicleRepository vehicleRepository;
    @Autowired
    private VehicleMakeRepository vehicleMakeRepository;
    @Autowired
    private VehicleModelRepository vehicleModelRepository;

    @Override
    public BaseRepository<Vehicle, String> getRepo() {
        return this.vehicleRepository;
    }

    public VehicleMake saveMake(VehicleMake vehicleMake){
        vehicleMakeRepository.save(vehicleMake);
        return vehicleMake;
    }

    public VehicleModel saveModel(VehicleModel vehicleModel){
        vehicleModelRepository.save(vehicleModel);
        return vehicleModel;
    }

    public VehicleModel getModelById(String modelId){
        return vehicleModelRepository.getOne(modelId);
    }

    public List<VehicleMake> makeList(){
        return vehicleMakeRepository.findAll();
    }

    public List<VehicleModel> modelList(String makeId){
        return vehicleModelRepository.findByMakeId(makeId);
    }
}
